﻿<?xml version="1.0" encoding="utf-8" ?>
<DbDataRequest connection="$DBConnection$" type="$ForumDBType$" defaultFormatter="bizobj ApprovalData(lastUpdateBy,approvalSet)">
	<SqlStatement hasResults="true">
		SELECT ApprovalData.id
			,ApprovalData.originalAction as ApprovalDataOriginalAction
			,ApprovalData.state as ApprovalDataState
			,ApprovalData.createdBy as ApprovalDataCreatedById
			,ApprovalData.lastupdatedate
			,Users.id as LastUpdateById
			,Users.userName as LastUpdateByUserName
			,Users.firstName as LastUpdateByFirstName
			,Users.lastName as LastUpdateByLastName
			,ApprovalData.nextApprover as ApprovalDataNextApprover
			,ApprovalSet.id as approvalSetid
			,ApprovalSet.objectType as approvalSetobjectType
			,ApprovalSet.saveHistory as approvalSetsaveHistory
			,ApprovalSet.moveToParent as ApprovalSetMoveToParentTree
			,(Select TOP 1 bizObjData from approvaldatachange where createdDate=(SELECT MAX(createdDate) from approvaldatachange where approvaldataid=approvaldata.id)) as rawbizObj
		FROM ApprovalData INNER JOIN ApprovalSet
		ON ApprovalData.approvalSetId=ApprovalSet.id INNER JOIN Users
		ON Users.id = ApprovalData.lastUpdateBy
		WHERE ApprovalSet.objectType=@typeName AND ApprovalData.objectId =@objectId
		ORDER BY ApprovalData.lastupdatedate desc
	</SqlStatement>
	<Param name="typeName" type="UnicodeVarChar" />
	<Param name="objectId" type="UniqueIdentifier" />
</DbDataRequest >
